<template>
  <div class="component-makeBudget">
    <div class="component-mainHeader">
      <div class="top">
        <div class="topleft">
          <p>
            <span class="iconfont" style="color:#1abc9a;margin-right:3px;">&#xe607;</span>基础参数表
          </p>
        </div>
        <div class="topright">
          <el-button type="info" @click="$router.go(0)">
            <span style="font-weight:700;margin-right:5px;" class="iconfont">&#xe662;</span>刷新
          </el-button>
        </div>
      </div>
    </div>
    <div class="component-listHeader">
      <div class="search-header">
        <div class="left-title">
          <p class="left-text">
            <span class="iconfont">&#xe61e;</span>
            基础参数表
          </p>
          <div class="right">
            <el-button @click="edit">{{editBtn?'进行编辑':'取消编辑'}}</el-button>
            <el-button style="width:70px;" @click="commit">保存</el-button>
          </div>
        </div>
      </div>
    </div>
    <div>
      <div class="table armorlistTable">
        <el-table
          ref="multipleTable"
          tooltip-effect="dark"
          :data="baseInfo"
          style="width: 1100px;margin:0 auto"
          border
        >
          <el-table-column label="序号" align="center" width="70" type="index"></el-table-column>
          <el-table-column label="名称" align="center">
            <template slot-scope="scope">
              <div> 光缆结算方式：{{scope.row.name}}</div>
            </template>
          </el-table-column>
          <el-table-column label="配置值" align="center" prop="matModel">
            <template slot-scope="scope">
              <span class="special">{{scope.row.name}}</span><el-input-number size="small" v-model="scope.row.confValue" controls-position="right" :disabled="editBtn"></el-input-number>
              <span v-if="scope.row.name=='段长加固定值'">米</span><span v-else>&nbsp;&nbsp;&nbsp;</span>
            </template>
          </el-table-column>
          <el-table-column label="开关" align="center">
            <template slot-scope="scope">
              <el-switch @change="changeTab(scope.$index,scope.row.isCheck)" v-model="scope.row.isCheck" :disabled="editBtn"></el-switch>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        editBtn: true,
        baseInfo:[],
        switchTab:true,
        sysConfig3:{},
      };
    },
    created() {},
    mounted() {
      this.baseConfigSelect();
    },
    methods: {
      // 查询接口
      baseConfigSelect() {
          let suCb = res => {
              res.data.data.sysConfig1.name="段长乘系数";
              res.data.data.sysConfig2.name="段长加固定值";
              this.sysConfig3 = res.data.data.sysConfig3;
              if(this.sysConfig3.confValue==0){
                res.data.data.sysConfig1.isCheck=false;
                res.data.data.sysConfig2.isCheck=false;
              }else if(this.sysConfig3.confValue==1){
                res.data.data.sysConfig1.isCheck=true;
                res.data.data.sysConfig2.isCheck=false;
              }else{
                res.data.data.sysConfig1.isCheck=false;
                res.data.data.sysConfig2.isCheck=true;
              }
            this.baseInfo = [res.data.data.sysConfig1,res.data.data.sysConfig2];
            console.log(this.baseInfo)
          },
          erCb = function(res) {
            console.log(res);
          },
          req = {
            url: "/api/web/sysConfig/getFiberLoss",
            methods: "post",
            data: {},
            success: suCb,
            error: erCb
          };
        this.$https(req);
      },
      //开关
      changeTab(index,val){
        if(index==0 & val==true){
          this.baseInfo[1].isCheck = false
        }
        if(index==1 & val==true){
          this.baseInfo[0].isCheck = false
        }
      },
      // 编辑按钮 事件处理函数
      edit(tab) {
        this.editBtn = !this.editBtn;
      },
      //保存
      commit(){
        if (!this.editBtn) {
          //0-两者都不选，1-选择光缆损耗系数，2-选择光缆损耗固定值
          if(this.baseInfo[0].isCheck==true){
            this.sysConfig3.confValue = 1
          }else if(this.baseInfo[1].isCheck==true){
            this.sysConfig3.confValue = 2
          }else{
            this.sysConfig3.confValue = 0
          }
          let that = this,
            suCb = res => {
              console.log(res);
              this.editBtn = !this.editBtn;
              that.$msg('保存成功')
            },
            erCb = function(res) {
              console.log(res);
            },
            req = {
              url: "/api/web/sysConfig/editFiberLoss",
              methods: "post",
              data: {
                sysConfig1:this.baseInfo[0],
                sysConfig2:this.baseInfo[1],
                sysConfig3:this.sysConfig3
              },
              success: suCb,
              error: erCb
            };
          that.$https(req);
        } else {
          this.$erMsg("先编辑，后保存！");
        }
      }
    }
  };
</script>

<style scoped>
  .component-listHeader .search-header {
    width: 1100px;
    box-sizing: border-box;
    border: 1px solid rgba(228, 228, 228, 1);
    border-bottom: none;
    background-color: rgba(255, 255, 255, 1);
    margin: 30px auto 0;
  }

  .component-listHeader .search-header .left-title {
    display: flex;
    justify-content: space-between;
    width: 100%;
    background-color: rgba(243, 243, 243, 1);
    height: 45px;
    box-sizing: border-box;
  }

  .component-listHeader .search-header .left-title .left-text {
    width: 20%;
    color: #666;
    line-height: 45px;
    font-family: "微软雅黑";
    font-weight: 400;
    font-size: 12px;
    text-align: left;
    margin: 0 0 0 30px;
  }

  .component-listHeader .search-header .right {
    width: 70%;
    display: flex;
    justify-content: flex-end;
    margin-right: 10px;
  }

  .component-listHeader .search-header .right button {
    padding: 0 15px;
    height: 30px;
    width: 110px;
    margin: 6px 5px;
    line-height: 30px;
    font-size: 14px;
    color: #1abc9c;
    background-color: #fff;
    border: 1px solid #ccc;
  }
  .el-form-item {
    width: 310px;
    margin-bottom: 20px !important;
  }
  .component-listHeader .search-header .right button:hover {
    background-color: #1abc9c;
    color: #fff;
  }
  .component-listHeader .search-header .right .right-select-margin {
    margin-top: 8px;
    margin-right: 8px;
  }
  /* 处理a链接 */
  a {
    text-decoration: none;
    color: #1abc9a;
  }
  a:hover {
    cursor: pointer;
  }

  .component-makeBudget .tabs-header {
    width: 1150px;
    box-sizing: border-box;
    margin: 0 auto 0;
  }

  .fl_container {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
  }
  .fl_container .fl_left {
    text-align: left;
  }
  .fl_container .fl_right {
    text-align: right;
  }

  /* 表格部分 */
  .budget {
    margin-top: 20px;
    width: 100%;
    overflow: hidden;
    background: #f8f8f8;
    height: 35px;
    line-height: 35px;
    font-size: 14px;
    border: 1px solid #e4e4e4;
    border-bottom: none;
    padding: 0 20px;
    box-sizing: border-box;
    font-size: 14px;
    color: #666;
  }
  .gcl .title {
    background: #f8f8f8;
    height: 35px;
    line-height: 35px;
    color: #666;
    padding: 0 20px;
    font-size: 14px;
    border: 1px solid #e4e4e4;
    border-bottom: none;
    text-align: left;
  }
  .budget .title {
    float: left;
  }
  .budget div:last-of-type {
    float: right;
  }
  .gcl .tabs {
    width: 1060px;
    margin: 20px;
    box-sizing: border-box;
  }

  .budgetTable table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    margin: 0 0 20px 0;
    padding: 0;
    border: none;
    font-size: 12px;
  }
  .budgetTable table td,
  th {
    height: 40px;
  }

  th {
    background-color: #f9fafc;
  }

  .gcl_footer {
    text-align: right;
    margin: 20px 0 0 0;
  }

  .gcl_footer .gcl_footer_bottom span {
    color: #1abc9c;
  }

  .gcl_footer .gcl_footer_bottom {
    margin-bottom: 10px;
    margin-right: 2px;
    font-size: 19px;
  }

  /* 双表格容器 */
  .dbTable {
    width: 1100px;
    margin: 0 auto;
    box-sizing: border-box;
    border: 1px solid #eee;
    border-top:none;
    display: flex;
    justify-content: space-around;
  }

  .dbTable .budgetTable {
    width: 500px;
  }

  .component-model .component-listHeader .search-header {
    width: 900px;
    box-sizing: border-box;
    border: 1px solid rgba(228, 228, 228, 1);
    background-color: rgba(255, 255, 255, 1);
    margin: 20px auto 0;
    border-bottom: 0;
  }

  .component-model .component-listHeader .search-header .left-title {
    display: flex;
    justify-content: space-between;
    width: 100%;
    background-color: rgba(243, 243, 243, 1);
    height: 45px;
    box-sizing: border-box;
  }

  .component-model .component-listHeader .search-header .left-title .left-text {
    width: 20%;
    color: #666;
    font-family: "微软雅黑";
    font-weight: 400;
    font-size: 12px;
    line-height: 45px;
    text-align: left;
    margin: 0 0 0 30px;
  }

  .component-model
  .component-listHeader
  .search-header
  .right
  .right-select-margin {
    margin-top: 6px;
    margin-right: 8px;
  }

  .component-model .table {
    width: 100%;
    margin: 0 auto;
  }

  .underTable {
    width: 100%;
    margin: 25px 0 0 15px;
    display: flex;
    justify-content: flex-start;
    align-items: baseline;
  }

  .tableTitle {
    text-align: center;
    margin: 15px auto;
  }
  .component_btnGroup {
    margin: 0 auto;
    padding: 20px;
    text-align: left;
    width: 1100px;
    box-sizing: border-box;
    border: 1px solid #eee;
    border-bottom: none;
  }
  .special{
    display: inline-block;background: #F5F7FA;height: 32px;vertical-align: middle;line-height: 32px;padding: 0 10px;width: 80px;
  }
</style>
